package  
{
	import flash.events.Event;
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.system.LoaderContext;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.external.ExternalInterface;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class Loading extends Sprite
	{
		private static var _instance:Loading = null;
		
		private var _loader:Loader = null;
		
		private var _webs:Object = null;
		
		public function Loading() 
		{
			this.addEventListener(Event.ADDED_TO_STAGE, onAddToStage, false, 0, true);
		}
		
		private function onAddToStage(e:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, onAddToStage);
			
			_instance = this;

			_webs = Starting.instance.webs;

			_loader = new Loader();
			var content:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComoplete);
			
			var request:URLRequest = new URLRequest();
			request.url = getSwfUrl('paigow');

			_loader.load(request);
		}
		
		private function onComoplete(e:Event):void
		{
			this.addChild(_loader);
			
			if (Starting.instance)
			{
				Starting.instance.remove();
			}
		}
		
		public function getSwfUrl(swfName:String):String
		{	
			var swf:String = "";
			if (typeof webs["vers"] != "undefined")
			{
				swf = webs["vers"][swfName];
			}
			
			var url:String = webs["flash_path"];
			return 	(url + swf);
			
		}

		public function get webs():Object { return _webs; }
		
		public static function get instance():Loading { return _instance; }
	}

}